package org.budo.support.spring.data.redis.serializer;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

public enum StringSerializer implements RedisSerializer<String> {
    INSTANCE;

    @Override
    public byte[] serialize(String string) throws SerializationException {
        return (null != string ? string.getBytes() : new byte[0]);
    }

    @Override
    public String deserialize(byte[] bytes) throws SerializationException {
        if (bytes.length > 0) {
            return new String(bytes);
        } else {
            return null;
        }
    }
}